# 503. 平均切分
# https://www.lanqiao.cn/problems/503/learning/
# Date: 2025/2/21

# 初始平面数为1
# 平面中每添加一条直线，平面数+1
# 新添加的直线与已有的直线的交点个数为N, 平面数再+N
# 交点的求法:
# w1  * x + b1 = w2 * x + b2 
# (w1 - w2) * x = b2 - b1
# x = (b2 - b1) / (w1 - w2) 

def get_planes_num(lines):
    def get_cross_point_num(visited, w1, b1):
        cross_points = set()
        count = 0  # 与其他直线交点的数量
        for w2, b2 in visited:  # 遍历所有已经添加的直线
            if w1 != w2:  # 两直线不平行
                # 计算交点
                x = (b2 - b1) / (w1 - w2)
                y = w1 * x + b1
                if (x, y) not in cross_points:
                    count += 1
                cross_points.add((x, y))
        return count

    visited = set()
    res = 1
    for w, b in lines:
        if (w, b) in visited:
            continue
        res += 1  # 平面中每添加一条直线，平面数+1
        res += get_cross_point_num(visited, w, b)
        visited.add((w, b))
    return res


if __name__ == '__main__':
    lines = [(1, 1), (1, 2), (1, 3), (4, 4)]
    print(get_planes_num(lines))
